﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace ProgramMain.NetVis
{
    public enum RangeStatus { Free, Active, Connection, CreateConnection }
    [XmlInclude(typeof(CrossBoxVis))]
    public class RangeBase
    {
        public RangeBase(Layers.VisLayer vis)
        {
            Vis = vis;
            if(Vis != null) Vis.AddRangeBase(this);
            ColorRange = Brushes.Black;

        }

        public virtual bool RemoveRectange()
        {
            if (Vis == null) return false;
            return Vis.RemoveRangeBase(this) > 0;
        }

        public RangeBase()
        {
            ColorRange = Brushes.Black;
        }
        [XmlIgnore]
        public virtual Layers.VisLayer Vis { get; private set; }
        private bool _visible = true;
        [XmlIgnore]
        public bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }
        [XmlIgnore]
        public int RangeID { get; set; }
        [XmlIgnore]
        public virtual Point VirtualPoint { get; set; }
        [XmlIgnore]
        public virtual Point Location
        {
            get { return Vis.GetLocation(VirtualPoint); }
        }
        [XmlIgnore]
        public virtual Size LocationSize
        {
            get
            {
                Size size = VirtualSize();
                return new Size((int)(size.Width * Vis.Scale), (int)(size.Height * Vis.Scale));
            }
        }

        public virtual int? ObjectID()
        {
            return null;
        }
        [XmlIgnore]
        public Brush ColorRange { get; set; }

         [XmlIgnore]
        public int width { get; set;}

         [XmlIgnore]
         public bool FillRange { get; set; }

         public virtual Size VirtualSize()
        { return Size.Empty; }

        [XmlIgnore]
        public bool IsShowHint = true;

        public virtual void SetCursor()
        { }

        [XmlIgnore]
        public string Hint { get; set; }
        [XmlIgnore]
        public int FibreID = 0;

        public virtual bool ClickRange(Point cursor)
        {
            Point toPoint = Location + LocationSize;

            return (Math.Min(Location.X, toPoint.X) < cursor.X && cursor.X < Math.Max(Location.X, toPoint.X)) &&
                   (Math.Min(Location.Y, toPoint.Y) < cursor.Y && cursor.Y < Math.Max(Location.Y, toPoint.Y));

        }

        protected RangeStatus _status;
        [XmlIgnore]
        public virtual RangeStatus Status
        {
            get { return _status; }
            set { _status = value; }
        }

        public virtual void Draw(Graphics layer)
        {
         //   if (this.FillRange)
                layer.FillRectangle(ColorRange, Location.X, Location.Y, LocationSize.Width, LocationSize.Height);
        //    else
                layer.DrawRectangle(new Pen(Color.Black, width), Location.X, Location.Y, LocationSize.Width, LocationSize.Height);


        }

        public virtual void CalcCoordinate(Point vPoint)
        { }

        public virtual void MouseClic(object sender, MouseEventArgs e)
        {
            MessageBox.Show("in Range");
        }

        public virtual void MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("in Range Double");
        }

        public virtual bool Shift(Size sizeShift)
        {
            return false;
        }
    }
}
